#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :1.0.2 bilibli排行、.py
# @Time      :2020/7/16 19:47
# @Author    :亮亮
# @说明       :
# @总结       :
import requests
from fake_useragent import UserAgent
from lxml import etree


def get_html(url):
    """
    得到网页内容
    :param url: 网址url
    :return: 网址内容
    """
    # 1.构建请求头
    headers = {
        "User-Agent": UserAgent().random
    }

    # 2.构建response返回对象
    response = requests.get(url, headers=headers)

    # 3.提取返回中的内容
    info = response.text

    return info


def re_html(info):
    # 1.构建解析对象
    e = etree.HTML(info)

    # 2.构建解析规则
    html_title = e.xpath('//div[@class="content"]/div[@class="info"]/a')

    # 3.提取出html文档中的文本
    contents = []
    for i in html_title:
        content = i.text
        contents.append(content)

    return contents


def folder_name(old_folder_name):



def main():
    # 1. 输入网址
    url = "https://www.bilibili.com/ranking"

    # 2.获取页面内容
    info = get_html(url)

    # 3.解析页面
    contents = re_html(info)

    # 4.输出
    for content in contents:
        print(content)


if __name__ == '__main__':
    main()
